- import_playbook: "/srv/web/infra/ansible/playbooks/include/virt-create.yml myhosts=odcs:odcs_stg"

- name: make the box be real
  hosts: odcs:odcs_stg
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  pre_tasks:
  - import_tasks: "{{ tasks_path }}/yumrepos.yml"

  roles:
  - base
  - rkhunter
  - nagios_client
  - hosts
  # openvpn on the prod frontend nodes
  #- { role: openvpn/client, when: "'odcs_frontend' in group_names" }
  - ipa/client
  - rsyncd
  - sudo
  - collectd/base

  tasks:
  - import_tasks: "{{ tasks_path }}/motd.yml"

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

- name: Set up odcs frontend service
  hosts: odcs_frontend:odcs_frontend_stg
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - "{{ vars_path }}/{{ ansible_distribution }}.yml"

  roles:
  - role: rabbit/user
    username: "odcs{{ env_suffix }}"
    sent_topics: ^org\.fedoraproject\.{{ env_short }}\.odcs\..*
  - mod_wsgi
  - role: nfs/client
    mnt_dir: '/mnt/fedora_koji'
    nfs_src_dir: 'fedora_koji'
    when: env != 'staging'
  - role: nfs/client
    mnt_dir: '/mnt/fedora_koji_prod'
    nfs_src_dir: 'fedora_koji'
    when: env == 'staging'
  - role: nfs/client
    mnt_dir: '/srv/odcs'
    nfs_src_dir: 'fedora_odcs_stg'
    nfs_mount_opts: "rw,hard,bg,intr,noatime,nodev,nosuid,nfsvers=3"
    when: env == 'staging'
    mount_stg: true
  - role: nfs/client
    mnt_dir: '/srv/odcs'
    nfs_src_dir: 'fedora_odcs'
    nfs_mount_opts: "rw,hard,bg,intr,noatime,nodev,nosuid,nfsvers=3"
    when: env != 'staging'
  - odcs/frontend

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

- name: Set up /mnt/koji on both the frontend and backend
  hosts: odcs:odcs_stg
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - role: nfs/client
    mnt_dir: '/mnt/fedora_koji'
    nfs_src_dir: 'fedora_koji'
    when: env != 'staging'

  # In staging, we mount fedora_koji as read only (see nfs_mount_opts)
  - role: nfs/client
    mnt_dir: '/mnt/fedora_koji_prod'
    nfs_src_dir: 'fedora_koji'
    when: env == 'staging'

  - role: nfs/client
    mnt_dir: '/srv/odcs'
    nfs_src_dir: 'fedora_odcs_stg'
    nfs_mount_opts: "rw,hard,bg,intr,noatime,nodev,nosuid,nfsvers=3"
    mount_stg: true
    when: env == 'staging'

  - role: nfs/client
    mnt_dir: '/srv/odcs'
    nfs_src_dir: 'fedora_odcs'
    nfs_mount_opts: "rw,hard,bg,intr,noatime,nodev,nosuid,nfsvers=3"
    when: env != 'staging'

  post_tasks:
  - file: src=/mnt/fedora_koji/koji dest=/mnt/koji state=link
    tags: nfs/client

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

- name: Set up odcs backend service
  hosts: odcs_backend:odcs_backend_stg
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - role: odcs/backend
  - role: keytab/service
    service: odcs
    owner_user: odcs
    owner_group: odcs

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

- name: Configure ODCS releng backends
  hosts: odcs_backend_releng
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - role: keytab/service
    service: odcs
    #  - role: rabbit/queue
    #username: "fmc{{ env_suffix }}"
    #queue_name: "{{ fmc_queue_name }}"
    #routing_keys: "{{ fmc_routing_keys }}"
    #thresholds:
    #  warning: 100
    #  critical: 1000
    #sent_topics: ^org\.fedoraproject\.{{ env_short }}\.odcs\..*
    #  - role: fmc

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"
